﻿using System.Linq;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Benecura.Interfaces.WebMetro.Classes.Helpers;

namespace Benecura.Interfaces.WebMetro
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            //BundleTable.Bundles.RegisterTemplateBundles();
            
            //Register bundles
            BundleTable.Bundles.Add(new JsCoreBundle());
            BundleTable.Bundles.Add(new JsPluginBundle());
            BundleTable.Bundles.Add(new JsCustomBundle());
            BundleTable.Bundles.Add(new CssCustomBundle());
            BundleTable.Bundles.Add(new CssPluginBundle());
            BundleTable.Bundles.Add(new CssCoreBundle());

#if DEBUG
            foreach (var bundle in BundleTable.Bundles)
            {
                bundle.Transforms.Clear();
            }
#endif
            BundleTable.Bundles.EnableDefaultBundles();
        }
    }
}